package com.itheima.health.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.utils.poi.POIUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@SuppressWarnings("ALL")
/**
 * @Description :预约管理
 * @author     :LD
 */
@RestController
@RequestMapping("ordersetting")
@Api(tags = "预约模块-预约设置")
public class OrderSettingController {
    @Reference
    private OrderSettingService orderSettingService;

    @PostMapping("importOrderSettings")
    @ApiOperation(value = "文件上传",notes = "上传excel模板")
    @ApiImplicitParam(name = "file",value = "文件对象",required = true,dataType = "__file")
    public Result importOrderSettings(@RequestParam("excelFile") MultipartFile file) throws IOException {
        List<String[]> orderSettings = POIUtils.readExcel(file);
        orderSettingService.importOrderSettings(orderSettings);
        return new Result(true);
    }

    @GetMapping("findSettingData/{year}/{month}")
    @ApiOperation(value = "查询预约设置信息",notes = "根据月份查询预约信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "year",value = "年",paramType = "path",dataType = "int"),
            @ApiImplicitParam(name = "month",value = "月",paramType = "path",dataType = "int"),
    })
    public Result findSettingData(@PathVariable("year")int year,@PathVariable("month")int month){
        return new Result(orderSettingService.findSettingData(year,month));
    }

    @PutMapping("updateNumberByOrderdate/{number}/{orderdate}")
    @ApiOperation(value = "修改预约设置信息",notes = "修改预约设置信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "number",value = "预约总数",paramType = "path",dataType = "int"),
            @ApiImplicitParam(name = "orderdate",value = "日期",paramType = "path",dataType = "String"),
    })
    public Result updateNumberByOrderdate(@PathVariable("number") int number,@PathVariable("orderdate") String orderdate){
        return new Result(orderSettingService.updateNumberByOrderdate(number,orderdate));
    }
}
